<?php
	require_once("../conexion/conexion.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<link href="../Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />

<!--<script src="../include_js/prototype.js" type="text/javascript"></script>-->
<script src="../include_js/jquery.js" type="text/javascript"></script>
<!--<script src="include_js/select_dependientes.js" type="text/javascript"></script>-->
<style>
.filaPar
{
	background:#81D371; 
	font-family:Verdana, Arial, Helvetica, sans-serif; 
    font-size:11px;
	text-align:center;
	vertical-align:middle;
	padding:3px;
}
.filaImpar
{
	background:#AEF1A1;
	font-family:Verdana, Arial, Helvetica, sans-serif; 
    font-size:11px;
	text-align:center;
	vertical-align:middle;
	padding:3px;
}
a:link {text-decoration:line-through; color:#0033FF;} /* Link no visitado*/
a:visited {text-decoration:none; color:#999900} /*Link visitado*/
a:hover {text-decoration:underline; color:#990000;} /*Mouse sobre el link*/
</style>
<script>
function Formulario(valor)
{
	
	numero = document.getElementById("tbPSMB").rows[valor].cells[0].innerText;
	cliente = document.getElementById("tbPSMB").rows[valor].cells[3].innerText;
	Codarea = document.getElementById("tbPSMB").rows[valor].cells[2].innerText;
	//alert(Codarea);
	window.open("Produccion/Ventana_PSMB.php?num="+numero+"&cliente="+cliente+"&area="+Codarea,"VentanaPSMB","width=810,height=550,scrollbars=yes");
}
</script>
</head>

<body>
<form name="form_lista_busqueda" method="post">
<?php
	extract($_POST); 
	$cmb_Analisis = $_POST['cmb_Analisis'];
	$cont = 0;
	if (is_numeric($txtFormulario)== true)
	{
		//echo "<br>";
		//echo "SI numero el formulario";
	}
	else
	{
	//echo "<br>";
	//echo "NO numero el formulario";
	//echo "<br>";
	}
	
	if (($txtFormulario=="Numero Formulario")or($txtFormulario=="")) {
		$txtFormulario="null";
		$cont++;
	}
	else
	{$txtFormulario="'".$txtFormulario."'";}
	
	if ($cmb_Muestreador==0) {
		$cmb_Muestreador="null";
		$cont++;
	}
	if ($cmb_Area==0) {
		$cmb_Area="null";
		$cont++;
	}
	
	if ($cmb_Cliente==0) {
		$cmb_Cliente="null";
		$cont++;
	}
	
	if ($cmb_TAnalisis==0){
		$cmb_TAnalisis="null";
		$cont++;
	}
	
	if ($cmb_Analisis==0){
		$cmb_Analisis="null";
		$cont++;
	}
	
	if ($txtFIni==""){
		$txtFIni="null";
		$cont++;
	}
	else
	{
		$FechaIni = explode("-", $txtFIni);
		$txtFIni = "$FechaIni[2]-$FechaIni[1]-$FechaIni[0]";
	}
	
	if ($txtFFin==""){
		$txtFFin="null";
		$cont++;
	}
	else
	{
		$FechaFin = explode("-", $txtFFin);
		$txtFFin = "$FechaFin[2]-$FechaFin[1]-$FechaFin[0]";
	}
	
	if($cont != 8)
	{
		$con = new Conexion();
		$con2 = $con->conexionBD("fpproduccion");
//		date_format(formulario.MFecha,'%d-%m-%y') as fecha,
//		date_format(ForFecha,get_format(date,'eur')) as fecha,
		$sql="select distinct
			formulario.ForNumero,
			AENombre,
			areaextraccion.AECod,
			CliRSocial,
			date_format(ForFecha,'%d/%m/%Y') as fecha,
			TSusNombre,
			ValPrecio
			from formulario 
			
			inner join clientes on
			clientes.CliRut=formulario.CliRut
			inner join analisis on
			analisis.ForNumero=formulario.ForNumero
			inner join tiposustancia on
			tiposustancia.TSusNum = analisis.TSusNum
			inner join sustancia on
			sustancia.SusCod=tiposustancia.SusCod
			inner join valor on
			valor.TSusNum=tiposustancia.TSusNum
			inner join areaextraccion on
			((areaextraccion.AECod=valor.AECod)and(areaextraccion.AECod=formulario.AECod))
			
			where 
			(($txtFormulario is NULL) or (formulario.ForNumero = $txtFormulario)) and
			((".$cmb_Muestreador." is NULL) or (formulario.MueRut = '".$cmb_Muestreador."')) and
			(($cmb_Area is NULL) or (formulario.AECod = $cmb_Area)) and
			((".$cmb_Cliente." is NULL) or (formulario.CliRut = '".$cmb_Cliente."')) and
			(($cmb_TAnalisis is NULL) or (sustancia.SusCod = $cmb_TAnalisis)) and
			(($cmb_Analisis is NULL) or (analisis.TSusNum = $cmb_Analisis)) and
			((($txtFIni is NULL) and ($txtFFin is NULL)) or DATE(ForFecha) BETWEEN '".$txtFIni."' and '".$txtFFin."')
			order by formulario.fornumero asc";		
		$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
		$fila = mysql_num_rows($res);
		//echo $fila;
		if($fila >0)
		{?>
		<table width="100%" border="0" class="uno" cellpadding="0" cellspacing="0" id="tbPSMB">
		<thead>
  		<tr>
    		<th width="11%">N&deg; Formulario</th>
    		<th width="22%">Nombre Area</th>
    		<th width="9%">Cod. Area</th>
			<th width="26%">cliente</th>
    		<th width="9%">Fecha</th>
    		<th width="14%">an&Aacute;lisis</th>
    		<th width="9%">valor uf</th>
  		</tr>
 		</thead>
		<?php
		$aux=1;
		$cont=1;
		while($reg = mysql_fetch_array($res))
		{
			if(($cont % 2)==0)
			{
				echo "<tr class=\"filaPar\" id='".$aux."'>";
				echo "<td width=\"11%\" class=\"filaPar\" id='".$aux."'><a href=javascript:Formulario($aux);>".$reg['ForNumero']."</a></td>";
				echo "<td width=\"22%\" class=\"filaPar\" >".$reg['AENombre']."</td>";
				echo "<td width=\"9%\" class=\"filaPar\" >".$reg['AECod']."</td>";
				echo "<td width=\"26%\" class=\"filaPar\" >".$reg['CliRSocial']."</td>";
				echo "<td width=\"9%\" class=\"filaPar\" >".$reg['fecha']."</td>";
				echo "<td width=\"14%\" class=\"filaPar\" >".$reg['TSusNombre']."</td>";
				echo "<td width=\"9%\" class=\"filaPar\" >".$reg['ValPrecio']."</td>";
				echo "</tr>";
			}
			else
			{
				echo "<tr class=\"filaImpar\" id='".$aux."'>";
				echo "<td width=\"11%\" class=\"filaImpar\"><a href=javascript:Formulario($aux);>".$reg['ForNumero']."</a></td>";
				echo "<td width=\"22%\" class=\"filaImpar\">".$reg['AENombre']."</td>";
				echo "<td width=\"9%\" class=\"filaImpar\">".$reg['AECod']."</td>";
				echo "<td width=\"26%\" class=\"filaImpar\">".$reg['CliRSocial']."</td>";
				echo "<td width=\"9%\" class=\"filaImpar\">".$reg['fecha']."</td>";
				echo "<td width=\"14%\" class=\"filaImpar\">".$reg['TSusNombre']."</td>";
				echo "<td width=\"9%\" class=\"filaImpar\">".$reg['ValPrecio']."</td>";
				echo "</tr>";
			}
			$aux++;
			$cont++;
		}
		$con->cerrarBD();
		?>
		</table>
		<?php }
		
		else
		{echo "<label style=\"font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;\">La b&uacute;squeda no gener&oacute; resultados.</label>";}
	}
	else
	{echo "<label style=\"font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;\">La b&uacute;squeda no gener&oacute; resultados.</label>";}
?>
</form>
</body>
</html>
